#include<bits/stdc++.h>
using namespace std;;

typedef struct BiTNode{
    int data;
    BiTNode *lchild, *rchild;
}BiTNode, *BiTree;

void CreateTree(BiTree &T){
    int x;
    cin >> x;
    if (x != -1){
        T = new BiTNode;
        T->data = x;
        CreateTree(T->lchild);
        CreateTree(T->rchild);
    }
}

int minDepth(BiTree T){
    if (T == NULL) {
       return 0;
    }
   
    if (T->lchild == NULL && T->rchild == NULL) {// 如果是叶子节点，深度为1
       return 1;
    }
   
    if (T->lchild == NULL) {// 如果左子树为空，只计算右子树
       return minDepth(T->rchild) + 1;
    }
   
    if (T->rchild == NULL) {// 如果右子树为空，只计算左子树
       return minDepth(T->lchild) + 1;
    }
   
    // 左右子树都不为空，取较小值
    int leftDepth = minDepth(T->lchild);
    int rightDepth = minDepth(T->rchild);
   
    return (leftDepth < rightDepth ? leftDepth : rightDepth) + 1;
}

int main(){
    BiTree T;
    CreateTree(T);
    int mind = minDepth(T);
    cout << mind << endl;
    return 0;
}
